import Vue from 'vue'
import Router from 'vue-router'
import navConfig from './nav.config'

Vue.use(Router)
const docsRoutefun = navConfig => {
  let route = []
  navConfig[0].groups.forEach(group => {
    group.list.forEach(nav => {
      console.log(nav)
      if (nav.path == '/log') {
        route.push({
          path: nav.path,
          name: nav.path,
          component: r => require.ensure([], () => r(require(`@/pages/log.vue`)))
        })
      } else {
        route.push({
          path: nav.path,
          name: nav.path,
          component: r => require.ensure([], () => r(require(`@/docs${nav.path}.md`)))
        })
      }

    })
  })
  return route
}

let docsRoute = docsRoutefun(navConfig)
docsRoute = docsRoute.concat([
  {
    path: '/',
    redirect: '/use',
    name: 'use',
    component: r => require.ensure([], () => r(require(`@/docs/use.md`)))
  }
])
export default new Router({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: docsRoute
})
